<?php

namespace App\Observers;

use App\Models\Message;
use App\Models\Wallet;

class WalletObserver
{
    /**
     * 监听创建前事件.
     *
     * @param Wallet $model
     * @return void
     */
    public function creating(Wallet $model)
    {

    }

    /**
     * 监听创建事件.
     *
     * @param Wallet $model
     * @return void
     */
    public function created(Wallet $model)
    {

    }

    public function updating(Wallet $model)
    {

    }

    /**
     * 监听更新后事件.
     *
     * @param Wallet $model
     * @return void
     */
    public function updated(Wallet $model)
    {
        if ($model->isDirty('balance')) {
            Message::create([
                'user_id' => $model->user_id,
                'title' => trans('api.balance_has_changed'),
                'content' => trans('api.your_balance_now_is') . $model->balance,
                'type' => Message::SYS,
            ]);
        }
    }

    /**
     * 监听删除事件.
     *
     * @param Wallet $model
     * @return void
     */
    public function deleting(Wallet $model)
    {

    }

    /**
     * 监听删除事件.
     *
     * @param Wallet $model
     * @return void
     */
    public function deleted(Wallet $model)
    {

    }

}
